using Digitalmes.Domain.Entities.Mes.Qualities;

namespace Digitalmes.Application.Mes.Qulities.Defects.Queries;

/// <summary>
/// 缺陷列表查询命令。
/// </summary>
public sealed record GetDefectListQuery() : IRequest<IResult<List<QcDefectDefineDto>>>;

internal sealed class GetDefectListQueryHandler(IRepository<QcDefectDefine> repo) : IRequestHandler<GetDefectListQuery, IResult<List<QcDefectDefineDto>>>
{
    public async Task<IResult<List<QcDefectDefineDto>>> Handle(GetDefectListQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetListAsync(m => m.Status == EnabledStatusEnum.Enabled, m => new { m.DefectType, m.Order }, false, cancellationToken);
        return Result.From(items.Adapt<List<QcDefectDefineDto>>());
    }
}
